﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics;
namespace MikeProject003_Console.MyClasses
{
    class Classes_001_Person
    {
        public int age;
        public int salary;
        const int ChildMax=20;

        Classes_001_Person[] childrens = new Classes_001_Person[ChildMax];
        int CountChildren = 0;

        public Classes_001_Person this[int i]
        {
            get
            {
                if (i >= 0 && i < CountChildren)
                    return childrens[i];
                else return childrens[0];
            }

            set
            {
                if (i == CountChildren)
                {
                    CountChildren++;
                    childrens[i]=value;
                }
            }
        }




    }

    class Classes_002_Array_in_class
    {
        public int read = 0;
        public int write = 0;
        int[] i = new int[5];

        public  void fill()
        {
            for(int y = 0; y < 5; y = y + 1)
            {
                i[y] = y * y;
            }
        }


        public int this[int y]
        {
            get
            {
                read++;
                return i[y];
            }


            set
            {
                write++;
                i[y] = value;
            }
        }

        

    }

    class Classes_003_MyOperator
    {
        public int i;


        public static Classes_003_MyOperator operator +(Classes_003_MyOperator a, Classes_003_MyOperator b)
        {
            int y;
            y = 4;

            Classes_003_MyOperator My = new Classes_003_MyOperator();
            My.i = a.i + b.i;

            

            
            return My;


        }

        

    }


    class classes_004_event_delegate
    {
        public static void FTestDel()
        {
            Console.WriteLine("Работает!!!");


        }


        public static void FTestDelBest()
        {
            Console.WriteLine("Работает отлично!!!");


        }



    }

    /// <summary>
    /// Публичный делегат
    /// </summary>
    /// <param name="s"></param>
    public delegate void Event_in_town (string s);

    class classes_005_event
    {
        public event Event_in_town Event_in_town_001;

        public classes_005_event()
        {

            this.Event_in_town_001 = new Event_in_town(initiall);
        }

        


        public void OnEvent_in_town(string s)
        {
            this.Event_in_town_001(s);
            
        }

        public void initiall (string s)
        {

            Console.WriteLine("initx");
        }
    }

    class classes_006_event_add
    {
        public classes_005_event Event_in_town_002;

        public classes_006_event_add(classes_005_event EIT)
        {
            this.Event_in_town_002 = EIT;

            this.Event_in_town_002.Event_in_town_001 += new Event_in_town(_speak);     
                      
        }

        void _speak(string s)
        {
            Console.WriteLine("ОК");
        }
        
    }


    class classes_007_event_arr:ArrayList
    {
        public MyEventArgs MyEvent = new MyEventArgs();
        public event SetEventHandler MySet;

        public void start()
        {


        }

        void OnChanged(MyEventArgs args)
        {
            if (MySet != null)
            {
                MySet(this, args);

            }

        }

        public override object this[int index]
        {
            get
            {
                return base[index];
            }
            set
            {
                MyEvent.item = value;
                OnChanged(MyEvent);
                if (MyEvent.permit)
                {
                    base[index] = value;
                    Console.WriteLine("Замена разрешена");
                }
                else
                    Console.WriteLine("Замена запрещена");
            }
            
        }
    }

    public class MyEventArgs : EventArgs
    {
         public object item;
         public bool permit;
    }

    
    public delegate void SetEventHandler (object sender, MyEventArgs args);

    class classes_008_Receiver1
    {
        classes_007_event_arr Arr_008;
        
        public classes_008_Receiver1 (classes_007_event_arr TheList)
        {
            Arr_008 = TheList;
            OnConnect();
        }
         

        public void OnConnect()
        {
            Arr_008.MySet += new SetEventHandler(chk);            
        }

        protected void chk(object sender, MyEventArgs args)
        {
            args.permit = false;
            Int32 _val;
            
            _val = Convert.ToInt32(args.item);

            if ((_val > 20) && (_val < 40))
            {
                args.permit = true;
            }
            
        }

    }

    class classes_009_Template<T>
    {
        static public void swap(ref T x, ref T y)
        {
            T temp;

            temp = x;

            x = y;


            y = temp;
        }



    }

    class classes_010_stack_elem<T>
    {
        public T item;
        public classes_010_stack_elem<T> next;

        public classes_010_stack_elem()
        {
            item = default(T);
            next = null;
        }


    }

   

    abstract class classes_011_stack_elems_overr<T>
    {
        

        abstract public void Remove();

        abstract public void Put(T t);
   
        abstract public T getitem();
    }

    class classes_012_stack_elems<T> : classes_011_stack_elems_overr<T>
    {
        public classes_010_stack_elem<T> Last;

        public override void Put(T t)
        {
            classes_010_stack_elem<T> NewItem = new classes_010_stack_elem<T>();

            NewItem.item = t;
            NewItem.next = Last;

            Last = NewItem;            
        }

        public override T  getitem()
        {
            return this.Last.item;

        }

        public override void Remove()
        {
            Last = Last.next;
        }



    }

    class classes_013_DebugPrint
    {

        [Conditional("DEBUG")]
        static public void PrintEntry(string name)
        {
            Console.WriteLine("Начал работать метод " + name);
        }




    }

}
